package com.example.sachon;

import com.example.sachon.R;
import android.os.Bundle;
import android.os.Handler;
import android.app.Activity;
import android.content.Context;
import android.content.Intent;
import android.content.SharedPreferences;
import android.telephony.TelephonyManager;
import android.view.Menu;

public class SA0000 extends Activity {
	private Handler mHandler = new Handler();
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_sa0000);
        loadProperties();
        
        
        TelephonyManager mgr = (TelephonyManager) getSystemService(Context.TELEPHONY_SERVICE);
        String _my_phone_num = mgr.getLine1Number();
        
        String _pnum = "";
        if( _my_phone_num.substring(1, 1)!="0")
        {
        	_pnum = "0"+_my_phone_num.substring(3);
        }else{
        	_pnum = _my_phone_num;
        }
        
        System.out.println(_pnum+"::"+ Const.getInstance().userInfo().getPhone_number());
        if( _pnum.equals(Const.getInstance().userInfo().getPhone_number()) == true)
        {
        	// 사용자 정보가 일치하는 경우 
        	move_main();
        }else{
        	// 사용자 정보가 일치하지 않는 경우 
        	move_login();
        }
       // move_login();
    }
    private void move_login(){
		mHandler.postDelayed(new Runnable() {
			public void run() {
				Intent intent = new Intent();
				intent.setClass(SA0000.this, SA0100.class);
								
				intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
				startActivity(intent);
				overridePendingTransition(0, 0);
				finish();
			}
		}, 1500); 
    }
    private void move_main(){
		mHandler.postDelayed(new Runnable() {
			public void run() {
				Intent intent = new Intent();
				intent.setClass(SA0000.this, SA0200.class);
								
				intent.setFlags(Intent.FLAG_ACTIVITY_CLEAR_TOP | Intent.FLAG_ACTIVITY_SINGLE_TOP);
				startActivity(intent);
				overridePendingTransition(0, 0);
				finish();
			}
		}, 1500); 
    }

	private void loadProperties() {
		SharedPreferences pref = getSharedPreferences("sachon", Context.MODE_PRIVATE);

		Const.getInstance().userInfo().setChon_id(pref.getString("chon_id", "") );
		Const.getInstance().userInfo().setUser_lv(pref.getString("user_lv", ""));
		Const.getInstance().userInfo().setUser_name(pref.getString("user_name", ""));
		Const.getInstance().userInfo().setPhone_number(pref.getString("phone_number", ""));


	}
	
    @Override
    public boolean onCreateOptionsMenu(Menu menu) {
        return true;
    }
}
